package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.AddressDao;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = AddressService.class)
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    //获取所有地址信息
    @Override
    public List<Address> getAddresses() {
        List<Address> addresses = addressDao.getAddresses();
//        System.out.println("业务层~~~~"+addresses);
        return addresses;
    }

    //添加地址信息
    @Override
    public void addAddr(Address address) {
        addressDao.addAddr(address);
    }

    @Override
    public void deleteById(Integer id) {
        addressDao.deleteById(id);
    }

    @Override
    public void update(Address address) {
        addressDao.update(address);
    }

    @Override
    public Address findById(Integer id) {
        return addressDao.findById(id);
    }

    //条件/分页查询
    @Override
    public PageInfo findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        List<Address> addressList = addressDao.findPage(queryString);
        return new PageInfo(addressList);
    }
}
